<?php
/**
 * Magento
 *
 * NOTICE OF LICENSE
 *
 * This source file is subject to the Academic Free License (AFL 3.0)
 * that is bundled with this package in the file LICENSE_AFL.txt.
 * It is also available through the world-wide-web at this URL:
 * http://opensource.org/licenses/afl-3.0.php
 * If you did not receive a copy of the license and are unable to
 * obtain it through the world-wide-web, please send an email
 * to license@magentocommerce.com so we can send you a copy immediately.
 *
 * DISCLAIMER
 *
 * Do not edit or add to this file if you wish to upgrade Magento to newer
 * versions in the future. If you wish to customize Magento for your
 * needs please refer to http://www.magentocommerce.com for more information.
 *
 * @category   design_default
 * @package    Mage
 * @copyright  Copyright (c) 2008 Irubin Consulting Inc. DBA Varien (http://www.varien.com)
 * @license    http://opensource.org/licenses/afl-3.0.php  Academic Free License (AFL 3.0)
 */
?>
    <?php $_code=$this->getMethodCode() ?>
    <ul id="payment_form_<?php echo $_code ?>" style="display:none">
        <!--li>
            <div class="input-box">
                <label for="<?php echo $_code ?>_cc_owner"><?php echo $this->__('Name on Card') ?> <span class="required">*</span></label><br/>
                <input type="text" title="<?php echo $this->__('Name on Card') ?>" class="required-entry input-text" id="<?php echo $_code ?>_cc_owner" name="payment[cc_owner]" value="<?php echo $this->getInfoData('cc_owner') ?>"/>
            </div>
        </li-->
        <li>
            <div class="input-box">
                <label for="<?php echo $_code ?>_cc_type"><?php echo $this->__('Credit Card Type') ?> <span class="required">*</span></label><br/>
                <select id="<?php echo $_code ?>_cc_type" name="payment[cc_type]" class="required-entry validate-cc-type-select">
                <?php $_ccType = $this->getInfoData('cc_type') ?>
                <?php foreach ($this->getCcAvailableTypes() as $_typeCode => $_typeName): ?>
                    <option value="<?php echo $_typeCode ?>" <?php if($_typeCode==$_ccType): ?>selected="selected"<?php endif ?>><?php echo $_typeName ?></option>
                <?php endforeach ?>
                </select>
            </div>
        </li>
        <li>
            <div class="input-box">
                <label for="<?php echo $_code ?>_cc_number"><?php echo $this->__('Credit Card Number') ?> <span class="required">*</span></label><br/>
                <input type="text" id="<?php echo $_code ?>_cc_number" name="payment[cc_number]" title="<?php echo $this->__('Credit Card Number') ?>" class="input-text validate-cc-number validate-cc-type" value="<?php echo $this->getInfoData('cc_number') ?>"/>
            </div>
        </li>
        <li>
            <div class="input-box">
                <label for="<?php echo $_code ?>_expiration"><?php echo $this->__('Expiration Date') ?> <span class="required">*</span></label><br/>
                <select id="<?php echo $_code ?>_expiration" style="width:140px;" name="payment[cc_exp_month]" class="required-entry">
                <?php $_ccExpMonth = $this->getInfoData('cc_exp_month') ?>
                <?php foreach ($this->getCcMonths() as $k=>$v): ?>
                    <option value="<?php echo $k?$k:'' ?>" <?php if($k==$_ccExpMonth): ?>selected="selected"<?php endif ?>><?php echo $v ?></option>
                <?php endforeach ?>
                </select>
                <?php $_ccExpYear = $this->getInfoData('cc_exp_year') ?>
                <select id="<?php echo $_code ?>_expiration_yr" style="width:103px;" name="payment[cc_exp_year]" class="required-entry">
                <?php foreach ($this->getCcYears() as $k=>$v): ?>
                    <option value="<?php echo $k?$k:'' ?>" <?php if($k==$_ccExpYear): ?>selected="selected"<?php endif ?>><?php echo $v ?></option>
                <?php endforeach ?>
                </select>
            </div>
        </li>
        <?php if ($this->hasSsCardType()): ?>
        <li id="<?php echo $_code ?>_cc_type_ss_div">
            <div class="input-box">
                <label for="<?php echo $_code ?>_issue"><?php echo $this->__('Switch/Solo Only') ?> <span class="required">*</span></label><br/>
                <ul style="margin:5px 0;">
                <li><?php echo $this->__('Issue Number') ?>:
                <input type="text" title="<?php echo $this->__('Issue Number') ?>" class="input-text validate-cc-ukss" id="<?php echo $_code ?>_cc_issue" name="payment[cc_ss_issue]" style="width:3em;" value="<?php echo $this->getInfoData('cc_ss_issue') ?>"/></li>
                <li><?php echo $this->__('Start Date') ?>:
                 <select id="<?php echo $_code ?>_start_month" style="width:140px;" name="payment[cc_ss_start_month]" class="validate-cc-ukss">
                 <?php $_ccStartMonth = $this->getInfoData('cc_ss_start_month') ?>
                 <?php foreach ($this->getCcMonths() as $k=>$v): ?>
                    <option value="<?php echo $k?$k:'' ?>" <?php if($k==$_ccStartMonth): ?>selected="selected"<?php endif ?>><?php echo $v ?></option>
                 <?php endforeach ?>
                 </select>
                 <select id="<?php echo $_code ?>_start_year" style="width:103px;" name="payment[cc_ss_start_year]" class="validate-cc-ukss">
                 <?php $_ccStartYear = $this->getInfoData('cc_ss_start_year') ?>
                 <?php foreach ($this->getSsStartYears() as $k=>$v): ?>
                    <option value="<?php echo $k?$k:'' ?>" <?php if($k==$_ccStartYear): ?>selected="selected"<?php endif ?>><?php echo $v ?></option>
                 <?php endforeach ?>
                 </select>
                </li>
                <li class="adv-container"></li>
               </ul>
            </div>
            <script type="text/javascript">
            var SSChecked<?php echo $_code ?> = function() {
                var elm = $('<?php echo $_code ?>_cc_type');
                if (elm.value=='SS') {
                    $('<?php echo $_code ?>_cc_type_ss_div').show();
                } else {
                    $('<?php echo $_code ?>_cc_type_ss_div').hide();
                }
            }

            Event.observe($('<?php echo $_code ?>_cc_type'), 'change', SSChecked<?php echo $_code ?>);
            SSChecked<?php echo $_code ?>();
            </script>
        </li>
        <?php endif; ?>
        <?php if($this->hasVerification()): ?>
        <li>
            <div class="input-box">
                <label for="<?php echo $_code ?>_cc_cid"><?php echo $this->__('Card Verification Number') ?> <span class="required">*</span></label><br/>
                <input type="text" title="<?php echo $this->__('Card Verification Number') ?>" class="required-entry input-text validate-cc-cvn" id="<?php echo $_code ?>_cc_cid" name="payment[cc_cid]" style="width:3em;" value="<?php echo $this->getInfoData('cc_cid') ?>"/>
                &nbsp;
                <a href="#" class="cvv-what-is-this"><?php echo $this->__('What is this?') ?></a>
            </div>
        </li>
        <?php endif; ?>
    </ul>
<script type="text/javascript">
Validation.addAllThese([
    ['validate-cc-ukss', 'Please enter issue number or start date for switch/solo card type.', function(v,elm) {
              var endposition;

              if (elm.id.match(/(.)+_cc_issue$/)) {
                  endposition = elm.id.indexOf('_cc_issue');
              } else if (elm.id.match(/(.)+_start_month$/)) {
                  endposition = elm.id.indexOf('_start_month');
              } else {
                  endposition = elm.id.indexOf('_start_year');
              }

              var prefix = elm.id.substr(0,endposition);

              var ccTypeContainer = $(prefix + '_cc_type');

              if (!ccTypeContainer) {
                    return true;
              }
              var ccType = ccTypeContainer.value;

              if(ccType!='SS'){
                  return true;
              }

              $(prefix + '_cc_issue').advaiceContainer
                = $(prefix + '_start_month').advaiceContainer
                = $(prefix + '_start_year').advaiceContainer
                = $(prefix + '_cc_type_ss_div').down('ul li.adv-container');

              var ccIssue   =  $(prefix + '_cc_issue').value;
              var ccSMonth  =  $(prefix + '_start_month').value;
              var ccSYear   =  $(prefix + '_start_year').value;

              if((!ccIssue && !ccSMonth && !ccSYear) ||
                 (!ccIssue && !ccSMonth && ccSYear)  ||
                 (!ccIssue && ccSMonth && !ccSYear)
              ){
                  return false;
              }

              return true;

    }]
]);
</script>